package com.android.basiclib.uitls;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.android.basiclib.R;

/**
 * 吐司工具类-兼容DToast-还是自己的布局还是自己的icon
 */
public class ToastUtils {

    public static final int LENGTH_SHORT = Toast.LENGTH_SHORT;

    public static void makeText(Context context, String str) {
        if (null == context || TextUtils.isEmpty(str)) {
            return;
        }
        View view = View.inflate(context,R.layout.custom_toast_normal_view,null);
        Toast toast = new Toast(context);
        toast.setView(view);
        TextView tvContent = (TextView) view.findViewById(R.id.tv_content);
        tvContent.setText(str);
        toast.setDuration(LENGTH_SHORT);
        toast.show();

    }

    public static void makeText(Context context, int resID) {
        if (null == context) {
            return;
        }
        View view = View.inflate(context,R.layout.custom_toast_normal_view,null);
        Toast toast = new Toast(context);
        toast.setView(view);
        TextView tvContent = (TextView) view.findViewById(R.id.tv_content);
        tvContent.setText(resID);
        toast.setDuration(LENGTH_SHORT);
        toast.show();


    }

    public static void showSuccessText(Context context, int resID) {
        if (null == context) {
            return;
        }

        View view = View.inflate(context,R.layout.custom_toast_bg_view,null);
        Toast toast = new Toast(context);
        toast.setView(view);
        TextView tvContent = (TextView) view.findViewById(R.id.tv_content);
        tvContent.setText(resID);
        toast.setDuration(LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();

    }

    public static void showSuccessText(Context context, String msg) {
        if (null == context) {
            return;
        }
        View view = View.inflate(context,R.layout.custom_toast_bg_view,null);
        Toast toast = new Toast(context);
        toast.setView(view);
        TextView tvContent = (TextView) view.findViewById(R.id.tv_content);
        tvContent.setText(msg);
        toast.setDuration(LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();


    }

    public static void showFailText(Context context, int resID) {
        if (null == context) {
            return;
        }
        View view = View.inflate(context,R.layout.custom_toast_bg_view,null);
        Toast toast = new Toast(context);
        toast.setView(view);
        TextView tvContent = (TextView) view.findViewById(R.id.tv_content);
        Drawable drawable = context.getResources().getDrawable(R.mipmap.icon_shibai);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        tvContent.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
        tvContent.setText(resID);
        toast.setDuration(LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();



    }

    public static void showFailText(Context context, String msg) {
        if (null == context) {
            return;
        }

        View view = View.inflate(context, R.layout.custom_toast_bg_view, null);
        Toast toast = new Toast(context);
        toast.setView(view);
        TextView tvContent = (TextView) view.findViewById(R.id.tv_content);
        Drawable drawable = context.getResources().getDrawable(R.mipmap.icon_shibai);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        tvContent.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
        tvContent.setText(msg);
        toast.setDuration(LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();

    }

    public static void showToastCenter(Context context, String msg) {
        if (null == context) {
            return;
        }

        View view = View.inflate(context, R.layout.custom_toast_bg_view, null);
        Toast toast = new Toast(context);
        toast.setView(view);
        TextView tvContent = (TextView) view.findViewById(R.id.tv_content);
        tvContent.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
        tvContent.setText(msg);
        toast.setDuration(LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();


    }



}
